package cn.kgc.liverservice.service;

import cn.kgc.bean.Wxfk;
import cn.kgc.myhousemapper.mapper.WxfkMapper;
import cn.kgc.service.WxfkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Component
public class WxfkServiceImpl implements WxfkService {
    @Resource
    WxfkMapper wxfkMapper;
    @Override
    public PageInfo<Wxfk> selectAllWxfk(Integer pageNum, Integer pageSize, Integer id,Integer houseid, Integer uid, String fkcontent, Date startTime, Date endTime) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy("startDate desc");
/*        WxfkExample wxfkExample=new WxfkExample();
        WxfkExample.Criteria criteria = wxfkExample.createCriteria();*/
        QueryWrapper<Wxfk> queryWrapper=new QueryWrapper<>();
        if (id!=null&&id!=0){
            queryWrapper.eq("id",id);
        }
        if (houseid!=null&&houseid!=0){
            queryWrapper.eq("houseid",houseid);
        }
        if (uid!=null&&uid!=0){
            queryWrapper.eq("uid",uid);
        }
        if (fkcontent!=null&&!fkcontent.equals("")){
            queryWrapper.like("fkcontent",fkcontent);
        }
        if (startTime!=null&&!startTime.toString().equals("Mon Jun 06 00:00:00 CDT 1988")&&endTime!= null&&!endTime.equals("Mon Jun 06 00:00:00 CDT 1988")){
            queryWrapper.le("startdate",startTime);
            queryWrapper.ge("enddate",endTime);

        }
        List<Wxfk> wxfks = wxfkMapper.selectList(queryWrapper);
        PageInfo<Wxfk> pageInfo=new PageInfo<>(wxfks);
        return pageInfo;
    }

    @Override
    public int update(Wxfk wxfk) {
        return wxfkMapper.updateById(wxfk);
    }

    @Override
    public int deleteWxfk(Integer id) {
        return wxfkMapper.deleteById(id);
    }
}
